package d2_collection_traverse;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 2024/6/4 Collection集合的遍历方式：迭代器Iterator遍历
 * Cjj 11:31
 */
public class CollectionDemo1 {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("李");
        c.add("王");
        c.add("张");
        System.out.println(c);

      //使用迭代器遍历集合
      //1.从集合对象中获取迭代器对象
        /*Iterator<String> it = c.iterator();
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println(it.next());*/


        //循环遍历迭代器
        Iterator<String> it = c.iterator();
        while (it.hasNext()) {
            String next = it.next();
            System.out.println(next);
        }
    }
}
